#ifndef GAMEWINDOW_H
#define GAMEWINDOW_H

#include <QMainWindow>
#include <QTimer>
#include <QKeyEvent>
#include <QVector>
#include <QPoint>
#include <QRandomGenerator>
#include <QPainter>
#include <QPixmap>

QT_BEGIN_NAMESPACE
namespace Ui { class GameWindow; }
QT_END_NAMESPACE

class GameWindow : public QMainWindow
{
    Q_OBJECT

public:
    GameWindow(QWidget *parent = nullptr);
    ~GameWindow();

protected:
    void paintEvent(QPaintEvent *event) override;
    void keyPressEvent(QKeyEvent *event) override;

private slots:
    void updateGame();

private:
    Ui::GameWindow *ui;
    QTimer *timer;
    QVector<QPoint> snake;
    QPoint food;
    int direction; // 0:上 1:右 2:下 3:左
    bool gameOver;
    int score;
    QPixmap foodImage;  // 食物图片
    QPixmap backgroundImage;  // 背景图片
    void generateFood();
    bool loadResources();  // 加载所有资源
};
#endif // GAMEWINDOW_H    